% tests filter operations
% input:  count ... approxmiate number of tests performed
% output: se    ... last used filter kernel
%         img   ... last used image
function [se img f] = testmorph(count)
  thresh = 0.00001;
  m = 1;
  for i = 1:count
    w = int16(rand()*10);
    h = int16(rand()*10);

    ws = int16(rand()*5)+1;
    hs = int16(rand()*5)+1;

    if (w < ws) || (h < hs)
      continue;
    end

    img = rand(h, w);
    se  = rand(hs,ws);

    miimg = imfilter(img, se);
    imimg = mifilter(img, se, 0); 

    miimg1 = imfilter(img, se, 'full');
    imimg1 = mifilter(img, se, 0, 'full'); 

    f = rand();
    miimg2 = imfilter(img, se, f);
    imimg2 = mifilter(img, se, f); 

    miimg3 = imfilter(img, se, f, 'full');
    imimg3 = mifilter(img, se, f, 'full'); 

    m = max(max(imabsdiff(miimg, imimg)));
    m = m + max(max(imabsdiff(miimg1, imimg1)));
    m = m + max(max(imabsdiff(miimg2, imimg2)));
    m = m + max(max(imabsdiff(miimg3, imimg3)));
    if m > thresh
      break;
    end
  end

  if m > thresh
    disp('Error!!!');
  else
    disp('No Error!');
  end

